//
//  MCTableViewController.m
//  MClient
//
//  Created by  史正烨 on 10-8-23.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "MCTableViewController.h"
#import "MCTableCell.h"

@implementation MCTableViewController

@synthesize tableview;


- (id)initWithStyle:(UITableViewStyle)style {
	if (self = [self init]) {
        // Custom initialization
		tableview = [[UITableView alloc] initWithFrame:CGRectZero style:style];
		tableview.dataSource = self;
		tableview.delegate = self;
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
	if (self = [self init]) {
        // Custom initialization
		tableview = [[UITableView alloc] initWithFrame:frame style:style];
		tableview.dataSource = self;
		tableview.delegate = self;
    }
    return self;
}


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	//将tableview添加到页面视图上
	if (!tableview) {
		tableview = [[UITableView alloc] initWithFrame:CGRectZero 
												 style:UITableViewStyleGrouped];
		tableview.dataSource = self;
		tableview.delegate = self;
	}
	tableview.frame = CGRectMake(0, 0, self.width, self.height) ;
	self.tableview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|
	UIViewAutoresizingFlexibleRightMargin|
	UIViewAutoresizingFlexibleTopMargin|
	UIViewAutoresizingFlexibleBottomMargin|
	UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
	[self.clientView addSubview:tableview];
}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
	NSLog(@"--------MCTableViewController viewDidUnload-----------");
	tableview.dataSource = nil;
	tableview.delegate = nil;
	[tableview release];
}


- (void)dealloc {
	tableview.dataSource = nil;
	tableview.delegate = nil;
	[tableview release];
    [super dealloc];
}

#pragma mark -- UITableView --
- (void)reloadData
{
	[self.tableview reloadData];
}

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section;
{
	return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	static NSString *s_tableCellIdentifer = @"BaseTableCell";
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:s_tableCellIdentifer];
	if (nil == cell) {
		cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:s_tableCellIdentifer] autorelease];
		cell.backgroundColor = [UIColor colorWithPatternImage:self.userDefaults.skin_bgMenuCellImg];
	}
	
	return cell;
}

- (UITableViewCell*)tableCell:(UITableView *)tableView withClass:(Class)aClassName withIdentifier:(NSString*)identifer
{
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifer];
	if (nil == cell) {
		if (aClassName == [MenuCell class]) {
			cell = [[[aClassName alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifer] autorelease];
		} else {
			cell = [[[aClassName alloc] initWithFrame:CGRectZero reuseIdentifier:identifer] autorelease];
		}
		
		cell.backgroundColor = [UIColor colorWithPatternImage:self.userDefaults.skin_bgMenuCellImg];
	}
	
	return cell;
}

- (BOOL) separator {
	return tableview.separatorStyle == UITableViewCellSeparatorStyleSingleLine;
}

- (void) setSeparator:(BOOL)flag {
	tableview.separatorStyle = flag ? UITableViewCellSeparatorStyleSingleLine : 
									  UITableViewCellSeparatorStyleNone;
}

@end
